package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bed")
@Api(tags = "床位管理相关接口")
public class BedController extends BaseController {

    @Autowired
    private BedService bedService;

    @GetMapping("/read/room/{roomId}")
    @ApiOperation(value = "根据房间id查询床位", notes = "传入房间id")
    public ResponseResult<List<BedVo>> readBedByRoomId(
            @ApiParam(value = "房间ID", required = true) @PathVariable("roomId") Long roomId) {
        List<BedVo> beds = bedService.getBedsByRoomId(roomId);
        return success(beds);
    }

    //创建床位
    @PostMapping("/create")
    public ResponseResult createBed(@RequestBody BedVo bedVo){
        bedService.addBed(bedVo);
        return ResponseResult.success();
    }

    //根据id号查询床号信息
    @GetMapping("/read/{id}")
    public ResponseResult getBedById(@PathVariable Long id){
        BedVo bedvo=bedService.getBedById(id);
        return ResponseResult.success(bedvo);
    }

    //更新床位信息
    @PutMapping("/update")
    public ResponseResult updateBed(@RequestBody BedVo bedVo){
        bedService.updateBed(bedVo);
        return ResponseResult.success("更新成功");
    }

    //删除床位
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteBed(@PathVariable Long id){
        bedService.deleteBed(id);
     return ResponseResult.success("删除成功");
    }
}
